package com.next

class BootStrap
{
    def init = { servletContext ->

        if (Role.count() < 1)
        {
            println 'init role data'

            def r = new Role()
            r.authority = 'ROLE_ADMINISTRATOR'
            r.description = '系统管理员'
            r.save flush: true
        }

        if (User.count() < 1)
        {
            println 'init contact data'

            def c = new User()
            c.username = 'ralf'
            c.password = '12345678'
            c.fullName = "尹何栋"
            c.cellphone = "18513603065"
            c.save flush: true

            c = new User()
            c.username = 'admin'
            c.password = 'Admin123456'
            c.fullName = "默认用户"
            c.cellphone = "18811432134"
            c.save flush: true
        }

        if (UserRole.count() < 1)
        {
            println 'init user role data'

            UserRole.create(User.findByUsername('ralf'), Role.findByAuthority('ROLE_ADMINISTRATOR'))
            UserRole.create(User.findByUsername('admin'), Role.findByAuthority('ROLE_ADMINISTRATOR'))
        }

        if (OpportunityStage.count() < 1) 
        {
            OpportunityStage ot = new OpportunityStage(name: "未发货")
            ot.save flush: true

            ot = new OpportunityStage(name: "已发货")
            ot.save flush: true

            ot = new OpportunityStage(name: "已完成")
            ot.save flush: true
        }

        if (ProductType.count() < 1) 
        {
            ProductType pt = new ProductType(name: "法式糕点")
            pt.allowAddSize = false
            pt.save flush: true

            pt = new ProductType(name: "蛋糕预定")
            pt.allowAddSize = true
            pt.save flush: true

            pt = new ProductType(name: "季节限定")
            pt.allowAddSize = false
            pt.save flush: true
        }

        if (AttachmentType.count() < 1) 
        {
            AttachmentType at = new AttachmentType(name: "产品LOGO")
            at.save flush: true

            at = new AttachmentType(name: "产品照片")
            at.save flush: true
        }

        if (Product.count() < 1) 
        {
            Product p = new Product()

            // 法式糕点
            p.name = "蛋白脆皮"
            p.type = ProductType.findByName("法式糕点")
            p.price = 4.5
            p.imageUrl = "https://cake.cindata.cn/static/images/dbcp_main.jpg"
            p.description = "经典法式泡沫甜点，口感轻快甘甜，蓝带高级烘焙师手工打发并烘焙，保证没颗柔软的内部和香脆的外表"
            p.save flush: true

            p = new Product()
            p.name = "马卡龙"
            p.type = ProductType.findByName("法式糕点")
            p.price = 12
            p.imageUrl = "https://cake.cindata.cn/static/images/mkl_main.jpg"
            p.description = "马卡龙外壳的蛋白小圆饼采用蓝带传统工艺烘焙手法，酥脆细腻。每盒包含八种口味，希望我们的认真与用心，能为您带来甜蜜的幸福滋味"
            p.save flush: true

            p = new Product()
            p.name = "什锦曲奇"
            p.type = ProductType.findByName("法式糕点")
            p.price = 12
            p.imageUrl = "https://cake.cindata.cn/static/images/sjqq_main.jpg"
            p.description = "优雅的白色，在珍珠的点缀下格外亮丽，100%使用猫山王榴莲造就了TA炙热的内心，只为懂得的人绽放"
            p.save flush: true

            p = new Product()
            p.name = "贝壳小蛋糕"
            p.type = ProductType.findByName("法式糕点")
            p.price = 18
            p.imageUrl = "https://cake.cindata.cn/static/images/bkxdg_main.jpg"
            p.description = "优雅的白色，在珍珠的点缀下格外亮丽，100%使用猫山王榴莲造就了TA炙热的内心，只为懂得的人绽放"
            p.save flush: true


            // 蛋糕预定
            p = new Product()
            p.name = "白巧克力慕斯"
            p.type = ProductType.findByName("蛋糕预定")
            p.price = 25
            p.imageUrl = "https://cake.cindata.cn/static/images/bqklms_main.jpg"
            p.description = "采用世界顶级巧克力Valrhona，被誉为巧克力中的爱马仕为主原料。使用此巧克力做出的慕丝口感更佳甜香细滑，奶香浓郁，每一口都是奢华的享受"
            p.save flush: true

            p = new Product()
            p.name = "草莓夹心蛋糕"
            p.type = ProductType.findByName("蛋糕预定")
            p.price = 25
            p.imageUrl = "https://cake.cindata.cn/static/images/cmjxdg_main.jpg"
            p.description = "蓝带烘焙师亲手制作，当天制作，新鲜送达。使用独家自制的草莓果泥，加上手工打发的鲜奶油，每一口都是天然的味道"
            p.save flush: true

            p = new Product()
            p.name = "草莓慕斯"
            p.type = ProductType.findByName("蛋糕预定")
            p.price = 25
            p.imageUrl = "https://cake.cindata.cn/static/images/cmms_main.jpg"
            p.description = "优雅的白色，在珍珠的点缀下格外亮丽，100%使用猫山王榴莲造就了TA炙热的内心，只为懂得的人绽放"
            p.save flush: true

            p = new Product()
            p.name = "百香果慕斯"
            p.type = ProductType.findByName("蛋糕预定")
            p.price = 25
            p.imageUrl = "https://cake.cindata.cn/static/images/bxgms_main.jpg"
            p.description = "蓝带高级烘焙师课程经典配方，当天制作，新鲜送达。香软的芒果加上酸香的百香果，这款芒果百香果慕丝，必将唇齿留香"
            p.save flush: true


            // 季节限定
            p = new Product()
            p.name = "冬日特选礼盒"
            p.type = ProductType.findByName("季节限定")
            p.price = 18
            p.imageUrl = "https://cake.cindata.cn/static/images/drtxlh_main.jpg"
            p.description = "礼盒包含三款经典法式小蛋糕，费南雪，歌剧蛋糕，巧克力榛果蛋糕"
            p.save flush: true
        }

        if (ProductItem.count() < 1) 
        {
            // 蛋糕预定
            // 白巧克力慕斯
            ProductItem pi = new ProductItem()
            pi.product = Product.findByName("白巧克力慕斯")
            pi.price = 25
            pi.size = "16"
            pi.description = "16寸的白巧克力慕斯"
            pi.save flush: true

            def p = Product.findByName("白巧克力慕斯")
            p.productItem = pi
            p.save flush: true

            // 草莓夹心蛋糕
            pi = new ProductItem()
            pi.product = Product.findByName("草莓夹心蛋糕")
            pi.price = 25
            pi.size = "16"
            pi.description = "16寸的草莓夹心蛋糕"
            pi.save flush: true

            p = Product.findByName("草莓夹心蛋糕")
            p.productItem = pi
            p.save flush: true

            // 草莓慕斯
            pi = new ProductItem()
            pi.product = Product.findByName("草莓慕斯")
            pi.price = 25
            pi.size = "16"
            pi.description = "16寸的草莓慕斯"
            pi.save flush: true

            p = Product.findByName("草莓慕斯")
            p.productItem = pi
            p.save flush: true

            // 百香果慕斯   
            pi = new ProductItem()
            pi.product = Product.findByName("百香果慕斯")
            pi.price = 25
            pi.size = "16"
            pi.description = "16寸的百香果慕斯"
            pi.save flush: true

            p = Product.findByName("百香果慕斯")
            p.productItem = pi
            p.save flush: true
        }

        if (Attachment.count() < 1)
        {
            Attachment at = new Attachment()
            at.fileName = "产品LOGO1"
            at.type = AttachmentType.findByName("产品LOGO")
            at.fileUrl = "https://cake.cindata.cn/static/images/LOGO1.jpg"
            at.save flush: true

            at = new Attachment()
            at.fileName = "产品LOGO2"
            at.product = Product.findByName("冬日特选礼盒")
            at.type = AttachmentType.findByName("产品LOGO")
            at.fileUrl = "https://cake.cindata.cn/static/images/drtxlh_main.jpg"
            at.save flush: true

            at = new Attachment()
            at.fileName = "产品LOGO3"
            at.product = Product.findByName("草莓慕斯")
            at.type = AttachmentType.findByName("产品LOGO")
            at.fileUrl = "https://cake.cindata.cn/static/images/cmms_main.jpg"
            at.save flush: true

            // 蛋白脆皮
            at = new Attachment()
            at.fileName = "蛋白脆皮"
            at.product = Product.findByName("蛋白脆皮")
            at.type = AttachmentType.findByName("产品照片")
            at.fileUrl = "https://cake.cindata.cn/static/images/dbcp_main.jpg"
            at.save flush: true

            at = new Attachment()
            at.fileName = "蛋白脆皮"
            at.product = Product.findByName("蛋白脆皮")
            at.type = AttachmentType.findByName("产品照片")
            at.fileUrl = "https://cake.cindata.cn/static/images/dbcp_detail1.jpg"
            at.save flush: true

            // 马卡龙
            at = new Attachment()
            at.product = Product.findByName("马卡龙")
            at.fileName = "马卡龙"
            at.type = AttachmentType.findByName("产品照片")
            at.fileUrl = "https://cake.cindata.cn/static/images/mkl_main.jpg"
            at.save flush: true

            at = new Attachment()
            at.product = Product.findByName("马卡龙")
            at.fileName = "马卡龙"
            at.type = AttachmentType.findByName("产品照片")
            at.fileUrl = "https://cake.cindata.cn/static/images/mkl_detail1.jpg"
            at.save flush: true

            at = new Attachment()
            at.product = Product.findByName("马卡龙")
            at.fileName = "马卡龙"
            at.type = AttachmentType.findByName("产品照片")
            at.fileUrl = "https://cake.cindata.cn/static/images/mkl_detail2.jpg"
            at.save flush: true

            at = new Attachment()
            at.product = Product.findByName("马卡龙")
            at.fileName = "马卡龙"
            at.type = AttachmentType.findByName("产品照片")
            at.fileUrl = "https://cake.cindata.cn/static/images/mkl_detail3.jpg"
            at.save flush: true

            at = new Attachment()
            at.product = Product.findByName("马卡龙")
            at.fileName = "马卡龙"
            at.type = AttachmentType.findByName("产品照片")
            at.fileUrl = "https://cake.cindata.cn/static/images/mkl_detail4.jpg"
            at.save flush: true


            // 什锦曲奇
            at = new Attachment()
            at.product = Product.findByName("什锦曲奇")
            at.fileName = "什锦曲奇"
            at.type = AttachmentType.findByName("产品照片")
            at.fileUrl = "https://cake.cindata.cn/static/images/sjqq_main.jpg"
            at.save flush: true

            at = new Attachment()
            at.product = Product.findByName("什锦曲奇")
            at.fileName = "什锦曲奇"
            at.type = AttachmentType.findByName("产品照片")
            at.fileUrl = "https://cake.cindata.cn/static/images/sjqq_detail1.jpg"
            at.save flush: true

            at = new Attachment()
            at.product = Product.findByName("什锦曲奇")
            at.fileName = "什锦曲奇"
            at.type = AttachmentType.findByName("产品照片")
            at.fileUrl = "https://cake.cindata.cn/static/images/sjqq_detail2.jpg"
            at.save flush: true


            // 贝壳小蛋糕
            at = new Attachment()
            at.product = Product.findByName("贝壳小蛋糕")
            at.fileName = "贝壳小蛋糕"
            at.type = AttachmentType.findByName("产品照片")
            at.fileUrl = "https://cake.cindata.cn/static/images/bkxdg_main.jpg"
            at.save flush: true

            at = new Attachment()
            at.product = Product.findByName("贝壳小蛋糕")
            at.fileName = "贝壳小蛋糕"
            at.type = AttachmentType.findByName("产品照片")
            at.fileUrl = "https://cake.cindata.cn/static/images/bkxdg_detail1.jpg"
            at.save flush: true

            at = new Attachment()
            at.product = Product.findByName("贝壳小蛋糕")
            at.fileName = "贝壳小蛋糕"
            at.type = AttachmentType.findByName("产品照片")
            at.fileUrl = "https://cake.cindata.cn/static/images/bkxdg_detail2.jpg"
            at.save flush: true

            at = new Attachment()
            at.product = Product.findByName("贝壳小蛋糕")
            at.fileName = "贝壳小蛋糕"
            at.type = AttachmentType.findByName("产品照片")
            at.fileUrl = "https://cake.cindata.cn/static/images/bkxdg_detail3.jpg"
            at.save flush: true


            // 白巧克力慕斯
            at = new Attachment()
            at.product = Product.findByName("白巧克力慕斯")
            at.fileName = "白巧克力慕斯"
            at.type = AttachmentType.findByName("产品照片")
            at.fileUrl = "https://cake.cindata.cn/static/images/bqklms_main.jpg"
            at.save flush: true

            at = new Attachment()
            at.product = Product.findByName("白巧克力慕斯")
            at.fileName = "白巧克力慕斯"
            at.type = AttachmentType.findByName("产品照片")
            at.fileUrl = "https://cake.cindata.cn/static/images/bqklms_detail1.jpg"
            at.save flush: true

            at = new Attachment()
            at.product = Product.findByName("草莓夹心蛋糕")
            at.fileName = "草莓夹心蛋糕"
            at.type = AttachmentType.findByName("产品照片")
            at.fileUrl = "https://cake.cindata.cn/static/images/cmjxdg_main.jpg"
            at.save flush: true

            at = new Attachment()
            at.product = Product.findByName("草莓慕斯")
            at.fileName = "草莓慕斯"
            at.type = AttachmentType.findByName("产品照片")
            at.fileUrl = "https://cake.cindata.cn/static/images/cmms_main.jpg"
            at.save flush: true

            at = new Attachment()
            at.product = Product.findByName("百香果慕斯")
            at.fileName = "百香果慕斯"
            at.type = AttachmentType.findByName("产品照片")
            at.fileUrl = "https://cake.cindata.cn/static/images/bxgms_main.jpg"
            at.save flush: true

            at = new Attachment()
            at.product = Product.findByName("冬日特选礼盒")
            at.fileName = "冬日特选礼盒"
            at.type = AttachmentType.findByName("产品照片")
            at.fileUrl = "https://cake.cindata.cn/static/images/drtxlh_main.jpg"
            at.save flush: true
        }
    }

    def destroy = {}
}
